package com.employees.action;

import java.io.InputStream;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.employees.bean.Employeeinfo;
import com.employees.dao.EmployeeDao;
import com.employees.service.EmployeeService;

public class EmployeeImage extends Action {

	private EmployeeService employeeService;
	


	public void setEmployeeService(EmployeeService employeeService) {
		this.employeeService = employeeService;
	}



	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		//显示图片
		String InfoId=request.getParameter("InfoId");
		Employeeinfo info=employeeService.getImage(Integer.parseInt(InfoId));
		
		InputStream input=info.getPhoto().getBinaryStream();
		ServletOutputStream out=response.getOutputStream();
		byte[] image=new byte[input.available()];
		int len=0;
		while((len=input.read(image))!=-1){
			out.write(image, 0, len);
			
		}
		out.flush();
		out.close();
		return null;
	}

	
}
